package com.miao.view
{
	import com.miao.utils.Consts;
	
	import mx.events.ListEvent;
	
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;
	
	public class ResourceTreeMediator extends Mediator
	{
		
		public static const NAME:String = "ResourceTreeMediator";
		
		public function ResourceTreeMediator(viewComponent:Object=null)
		{
			super(NAME, viewComponent);
			
			initView();
		}
		
		private function initView():void{
			view.tree.labelField="@label";
			view.tree.showRoot=false;
			view.tree.doubleClickEnabled=true;
			view.tree.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, handleTreeEvt);
		}
		
		private function handleTreeEvt(e:ListEvent):void{
			if(e.type == ListEvent.ITEM_DOUBLE_CLICK){
				sendNotification(Consts.PLAY_URL, view.tree.selectedItem as XML);
			}
		}
		
		public function setData(xml:XML):void{
			view.tree.dataProvider = xml;
		}
		
		public function setSelected(data:Object):void{
			view.treeHighlightItem = data;
			view.tree.invalidateList();
		}
		
		private function get view():ResourceTree
		{
			return viewComponent as ResourceTree;
		}
	}
}